Tolerant Colors
Tolerant Colors
Tolerant colors allow you to change the current color environment if the
available colors are not sufficiently close to those your application needs.
When your window becomes the frontmost window on a device, its palette's
colors are given p reference. Each tolerant color is compared to the best match
available in the current color environment. (In a multi-screen environment
this comparison is done for each device on which the window is drawn.) When
the difference between your color and the best available match is greater than
the tolerance you specify, the Palette Manager
loads an exact match into the CLUT.
The Palette Manager compares the tolerance value associated with each
palette entry to a measure of the difference between two RGB color values. This
difference is an approximation of the distance between the two points as
measured in a Cartesian coordinate system where the axes are the unsigned red,
green, and blue values. The distance formula used is
RGB = maximum of (abs(Red1 - Red2), abs(Green1 - Green2), abs(Blue1
- Blue2))
A tolerance value of 0x0000 means that only an exact match is accep table.
(Any value of 0x0xxx other than 0x0000 is reserved and should not be used in
applications.) A value of 0x5000 is generally sufficient to allow matching
without updates in well-balanced color environments, such as those provided
by the default palettes.
If your palette requires more colors than the number of unreserved table
indices, the Palette Manager checks to see if some other palette has
reserved indices for animation. If so, it cancels their reservation and makes
their indices available for your palette.
If you ask for more colors than are available on a device, the
Palette Manager cannot honor your request. Color requests that cannot be
met default to courteous colors, and the Color Manager selects the best color
available. (That selection will of necessity match one of the colors elsewhere
in your palette, since the Palette Manager runs out of colors only after it
has given your palette all that are available. This procedure works as well as
possible for a given device, but, of course, works better if your window is
moved to a deeper device where the request can be met.)
Note that two tolerant entries may match to the same index even if space is not
the problem. For instance, when all indices are initially assigned to black,
activating a palette with 256 shades of gray with tolerance 0x2000 uses up
four indices, that being sufficient to match all 256 shades within a tolerance
of 0x2000. If the tolerance were decreased to 0x1000, then eight indices
would be altered.
On direct devices, tolerant entries always match exactly.